<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input name="orgId"  type="hidden" id="treeId"/>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属机构：</label>
                            <div class="col-sm-8">
                                <input class="form-control" type="text" name="orgName" onclick="selectDeptTree()" readonly="true" id="orgName">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="mustInput">*</span>所属充电站：</label>
                            <div class="col-sm-8">
                                <select id="stationId" name="stationId" class="selectpicker show-tick form-control" title="请选择">
                                    <option th:each="station,stationStat:${station}" th:value="${station.id}" th:text="${station.name}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="mustInput">*</span>充电桩编号：</label>
                            <div class="col-sm-8">
                                <input id="code" name="code" data-null="请输入充电桩编号" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="mustInput">*</span>桩位编号：</label>
                            <div class="col-sm-8">
                                <input id="num" name="num" data-null="请输入桩位编号" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">品牌厂商：</label>
                            <div class="col-sm-8">
                                <select id="trademark" name="trademark" class="selectpicker show-tick form-control" title="请选择">
                                    <option th:each="trademark,trademarkStat:${trademarkList}" th:value="${trademark.id}" th:text="${trademark.name}"></option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">型号：</label>
                            <div class="col-sm-8">
                                <input id="type" name="type" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">电压：</label>
                            <div class="col-sm-8">
                                <input id="voltage" name="voltage" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">额定功率：</label>
                            <div class="col-sm-8">
                                <input id="power" name="power" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">电流：</label>
                            <div class="col-sm-8">
                                <select id="electricity" name="electricity" class="selectpicker show-tick form-control" title="请选择" th:with="type=${@dict.getType('stake_electricity')}">
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">国家接口标准：</label>
                            <div class="col-sm-8">
                                <select id="standard" name="standard" class="selectpicker show-tick form-control" title="请选择"th:with="type=${@dict.getType('stake_standard')}">
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">桩类型：</label>
                            <div class="col-sm-8">
                                <select id="stakeType" name="stakeType" class="selectpicker show-tick form-control" title="请选择" th:with="type=${@dict.getType('stake_type')}">
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </div>
                        </div>
                        <!-- 附加信息结束 -->
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <div class="btn btn-primary" onclick="save()">提交</div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script>

    /*司机管理-新增-选择部门树*/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: ctx + "system/dept/selectDeptTree/" + deptId,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#orgName").val(body.find('#treeName').val());
        layer.close(index);
    }

    $(function() {
        laydate.render({
            elem: '#onboardTime',type: 'datetime'
        });
    });
    function save() {
        // 必输校验
        var hasFlag = 0;
        var stationId = $("#stationId").val();
        if(stationId==null || stationId==''){
            hasFlag = 1;
            layer.alert("请选择所属充电站");
        }
        $('#signupForm input').each(function (index, item) {
            var val = $.trim($(item).val());
            var dataNull = $(item).data('null');
            if (!val && !hasFlag && dataNull) {
                hasFlag = 1;
                layer.msg(dataNull);
            }
        })
        if (hasFlag) {
            return;
        }
        $.ajax({
            cache: true,
            type: "POST",
            url: ctx+"cdzStake/addSave",
            data: $('#signupForm').serialize(), // 你的formid
            async: false,
            error: function (request) {
                parent.layer.alert("网络超时");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });
    }
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
</body>
</html>
